package cloud.maque.admin.impl;

import cloud.maque.admin.domain.entity.MqUserExt;
import cloud.maque.admin.mapper.MqUserExtMapper;
import cloud.maque.admin.service.MqUserExtService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 4color
 * @description 用户扩展信息
 * @date 2023-03-17
 */
@Service
public class MqUserExtServiceImpl extends ServiceImpl<MqUserExtMapper, MqUserExt> implements MqUserExtService {

    @Override
    public List<MqUserExt> list(MqUserExt ext) {
        QueryWrapper<MqUserExt> wrapper = new QueryWrapper<>();
        if (!StrUtil.isEmptyIfStr(ext.getUserId())) {
            wrapper.lambda().eq(MqUserExt::getUserId, ext.getUserId());
        }

        if (!StrUtil.isEmptyIfStr(ext.getFieldName())) {
            wrapper.lambda().eq(MqUserExt::getFieldName, ext.getFieldName());
        }

        wrapper.lambda().orderByAsc(MqUserExt::getCreateAt);
        List<MqUserExt> lists = this.baseMapper.selectList(wrapper);
        return lists;
    }

    @Override
    public List<MqUserExt> listByUserId(String userId) {
        MqUserExt userExt = new MqUserExt();
        userExt.setUserId(userId);
        return list(userExt);
    }

    @Override
    public Boolean deleteUser(String userId) {

        QueryWrapper<MqUserExt> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(MqUserExt::getUserId, userId);

        return this.baseMapper.delete(queryWrapper) > 0 ? true : false;
    }


}
